package Spring5.第二章.demo2_3_单例模式;

/**
 * 双重检查锁的单例模式
 *
 */
public class LazyDoubleCheckingSingleton {
    private volatile static LazyDoubleCheckingSingleton lazyDoubleCheckingSingleton = null;

    private LazyDoubleCheckingSingleton(){}

    public static LazyDoubleCheckingSingleton getInstance() {
        if (lazyDoubleCheckingSingleton == null) {
            synchronized (LazyDoubleCheckingSingleton.class) {
                if (lazyDoubleCheckingSingleton == null) {
                    lazyDoubleCheckingSingleton = new LazyDoubleCheckingSingleton();
                    // 1 分配内存给这个对象
                    // 2 初始化对象
                    // 3 设置lazy指向刚分配的内存地址
                }
            }
        }
        return lazyDoubleCheckingSingleton;
    }
}
